package com.agency8x.model;

import com.agency8x.model.base.BaseDiamondTransactionModel;
import com.agency8x.util.DateTimeUtil;
import com.agency8x.util.RegexUtil;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page;

/**
 * Recharge model.
 * 数据库字段名建议使用驼峰命名规则，便于与 java 代码保持一致，如字段名： userId
 */
@SuppressWarnings("serial")
public class DiamondTransactionModel extends BaseDiamondTransactionModel<DiamondTransactionModel> {
	
	public static final DiamondTransactionModel me = new DiamondTransactionModel().dao();
	
	/**
	 * 所有 sql 与业务逻辑写在 Service 中，在此放在 Model 中仅为示例
	 */
	public Page<DiamondTransactionModel> paginate(int pageNumber, int pageSize,String searchword,String beginDate,String endDate) {
		String sql = "select d.*, u.nickname ";
        String sqlFrom = "from t_finance_transaction_details d left join t_user u on d.user_id=u.user_id";
        sqlFrom+=" where d.trade_type in (4,5,6) ";
        if(DateTimeUtil.validateDate(beginDate)){
            sqlFrom = sqlFrom + " and d.create_time > '" + beginDate + " 00:00:00'";
        }
        if (DateTimeUtil.validateDate(endDate)) {//起始
            sqlFrom = sqlFrom + " and d.create_time < '" + endDate + " 23:59:59'";
        }

        if (StrKit.notBlank(searchword)) {
            if (RegexUtil.isNumeric(searchword)) {
                sqlFrom = sqlFrom + " and (u.user_id like '%" + searchword+"%' or u.nickname like '%"+searchword+"%')";
            }else{
                sqlFrom = sqlFrom + " and u.nickname like '%" + searchword+"%'";
            }
        }
        sqlFrom = sqlFrom + " order by d.id desc";
		return paginate(pageNumber, pageSize, sql,sqlFrom);
	}
	
	public String getTradeTypeText(){
		Short trade_type=getTradeType();
		String stype="";
		// 1:充值,2:返现;3:提现;4:赠送;5:领取;6:转换
		switch(trade_type){
		case 1:
			stype="充值";
			break;
		case 2:
			stype="返现";
			break;
		case 3:
			stype="提现";
			break;
		case 4:
			stype="赠送";
			break;
		case 5:
			stype="领取";
			break;
		case 6:
			stype="转换";
			break;
		}
		return stype;
	}
	public String getTransformTypeText(){
		Short trade_type=this.getTransformAmountType();
		String stype="";
		// 转换类别(1:钻石(充值);2:泊众房卡(娱乐);3:网狐金豆(游戏))
		switch(trade_type){
		case 1:
			stype="钻石充值";
			break;
		case 2:
			stype="泊众房卡";
			break;
		case 3:
			stype="网狐金豆";
			break;
		}
		return stype;
		
	}

	public String getCreateTimeText() {
		return DateTimeUtil.formatSqlServerDateTime(getCreateTime());
	}
}


